package com.ctcnit.templatepro.global

import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.widget.ImageView
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.hb.trans.global.RoundRadiusCrop

@GlideModule
class MyGlideModule : AppGlideModule() {

    companion object {

        fun loadCircularWithSex(
            context: Context,
            url: String,
            target: ImageView,
            sex: Int = 1
        ) {
            GlideApp.with(context)
                .load(url)
                .circleCrop()
                .into(target)
        }

        fun loadCircular(
            context: Context,
            url: String,
            target: ImageView,
            placeHolder: Int,
            error: Int
        ) {
            GlideApp.with(context)
                .load(url)
                .placeholder(placeHolder)
                .error(error)
                .circleCrop()
                .into(target)
        }

        /**
         * @param roundRadius 圆角弧度 单位 dp
         */
        fun loadRoundRadius(
            context: Context,
            url: String?,
            target: ImageView,
            roundRadius: Int,
            placeHolder: Int,
            error: Int
        ) {
            GlideApp.with(context)
                .load(url)
                .placeholder(placeHolder)
                .error(error)
                .apply(RequestOptions.bitmapTransform(RoundRadiusCrop(context, roundRadius)))
                .into(target)
        }

        fun loadRoundRadiusWithSex(
            context: Context,
            url: String?,
            target: ImageView,
            roundRadius: Int,
            placeHolder: Int,
            error: Int,
            sex: Int = 1
        ) {
            GlideApp.with(context)
                .load(url)
                .placeholder(placeHolder)
                .error(error)
                .apply(RequestOptions.bitmapTransform(RoundRadiusCrop(context, roundRadius)))
                .into(target)
        }


        fun load(
            context: Context,
            path: String?,
            target: ImageView,
            palceholder: Int = 0,
            error: Int = 0
        ) {
            GlideApp.with(context)
                .load(path)
                .centerCrop()
                .placeholder(palceholder)
                .error(error)
                .into(target)
        }

        fun loadDefault(
            context: Context,
            path: String?,
            target: ImageView,
            palceholder: Int = 0,
            error: Int = 0
        ) {
            GlideApp.with(context)
                .load(path)
                .placeholder(palceholder)
                .error(error)
                .into(target)
        }

        fun load(
            context: Context,
            path: String?,
            target: ImageView,
            listener: RequestListener<Drawable>?,
            palceholder: Int = 0,
            error: Int = 0
        ) {
            GlideApp.with(context)
                .load(path)
                .listener(listener)
                .placeholder(palceholder)
                .error(error)
                .into(target)
        }

        fun load(context: Context, bitmap: Bitmap, target: ImageView) {
            GlideApp.with(context)
                .load(bitmap)
                .into(target)
        }

        fun load(context: Context, resId: Int, target: ImageView) {
            GlideApp.with(context)
                .load(resId)
                .into(target)
        }


    }


}